//
//  DatePickerViewController.m
//  SKStock
//
//  Created by InYong Shon on 11. 1. 24..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "DatePickerViewController.h"


@implementation DatePickerViewController

@synthesize delegate = _delegate;


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

	
	[_datePicker setDatePickerMode:UIDatePickerModeDate];
	
	_dateFormatter = [[NSDateFormatter alloc] init];
	[_dateFormatter setDateFormat:@"yyyy/MM/dd"];
	
	if(_strDate != nil){
		NSDate* date = [_dateFormatter dateFromString:_strDate];
		[_datePicker setDate:date animated:YES];
	}else{
		NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];
		[_datePicker setDate:date animated:YES];
	}
	
//	[_dateFormatter setDateStyle:kCFDateFormatterMediumStyle];
	
//	kCFDateFormatterNoStyle = 0,
//	kCFDateFormatterShortStyle = 1,
//	kCFDateFormatterMediumStyle = 2,
//	kCFDateFormatterLongStyle = 3,
//	kCFDateFormatterFullStyle = 4	
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
//	LOG_DEALLOC(@"======== Start");
	G__SAFE_FREE(_datePicker);
	G__SAFE_FREE(_dateFormatter);
	_delegate = nil;
	
    [super dealloc];
//	LOG_DEALLOC(@"======== End");
}

#pragma mark -
#pragma mark Control Actions
- (IBAction)doneButtonAction:(id)sender {
	[_delegate datePickerViewControllerDidSelected:self dateStr:[_dateFormatter stringFromDate:_datePicker.date]];
}

- (IBAction)cancelButtonAction:(id)sender {
	[_delegate datePickerViewControllerDidCancelled:self];
}

- (void)initDatePosition:(NSString*)str{
	_strDate = str;
}

@end
